val input = TextIO.openIn("input.txt");

fun printInt (a:int) =
    print(Int.toString(a)^" ");

fun getInt () =
    Option.valOf (TextIO.scanStream (Int.scan StringCvt.DEC) input);
    
fun printIntList ( [] ) = ()
  | printIntList ( x::xs ) = 
    let
	val tmp = printInt(x)
    in
	printIntList(xs)
    end;

fun getIntList ( 0 ) = []
  | getIntList ( N:int) = getInt()::getIntList(N-1);

(*  完成Begin和End间代码 *)    
(*****Begin*****)
fun PrefixSum(l) =   
  let   
    fun sumHelper(_, _, []) = []   
      |sumHelper(i, acc, x::xs) = (acc + x) :: sumHelper(i + 1, acc + x, xs)  
  in   
    sumHelper(0, 0, l)   
  end;

fun fastPrefixSum(l) =   
  let   
    fun sumHelper(_, []) = [] 
      |sumHelper(acc, x::xs) = (acc + x) :: sumHelper(acc + x, xs)  
  in   
    sumHelper(0, l)   
  end;


(*****End*****)

val L = getIntList(3);
printIntList (PrefixSum L);
printIntList (fastPrefixSum L);
